package com.mfin.bs.mgr.impl;

import com.mfin.bom.factory.CustomerInformationFactory;
import com.mfin.bom.factory.interfaces.ICustomerInformationFactory;
import com.mfin.bom.interfaces.ICustomer;
import com.mfin.bom.interfaces.IPartner;
import com.mfin.bs.mgr.interfaces.ICustomerInformationManager;
import com.mfin.vo.CustomerVO;
import com.mfin.vo.PartnerVO;

public class CustomerInformationManager extends BaseManager implements
		ICustomerInformationManager {

	ICustomerInformationFactory customerInformationFactory = new CustomerInformationFactory();

	@Override
	public CustomerVO getCustomer(CustomerVO customer) {
		logMethodBegin("CustomerInformationManager", "getCustomer");

		customerInformationFactory
				.setPersistenceGovernor(getPersistenceGovernor());
		ICustomer bomCustomer = customerInformationFactory
				.getCustomerInformation(customer);

		map(bomCustomer, customer, false, true);

		logMethodEnd("CustomerInformationManager", "getCustomer");
		return customer;
	}

	@Override
	public CustomerVO updateCustomer(CustomerVO customer) {
		logMethodBegin("CustomerInformationManager", "updateCustomer");

		customerInformationFactory
				.setPersistenceGovernor(getPersistenceGovernor());
		ICustomer bomCustomer = customerInformationFactory
				.getCustomerInformation(customer);

		map(customer, bomCustomer, false, false);
		map(bomCustomer, customer, false, true);

		logMethodEnd("CustomerInformationManager", "updateCustomer");
		return customer;
	}

	@Override
	public PartnerVO getPartner(PartnerVO partnerVO) {
		logMethodBegin("CustomerInformationManager", "getPartner");

		customerInformationFactory
				.setPersistenceGovernor(getPersistenceGovernor());
		IPartner bomPartner = customerInformationFactory
				.getPartnerInformation(partnerVO);

		map(bomPartner, partnerVO, false, true);
		if (partnerVO instanceof CustomerVO) {
			map(bomPartner.getCustomer(), (CustomerVO) partnerVO, false, false);
		}

		logMethodEnd("CustomerInformationManager", "getPartner");
		return partnerVO;
	}

	@Override
	public PartnerVO updatePartner(PartnerVO partnerVO) {
		logMethodBegin("CustomerInformationManager", "updatePartner");

		customerInformationFactory
				.setPersistenceGovernor(getPersistenceGovernor());

		IPartner bomPartner = customerInformationFactory
				.getPartnerInformation(partnerVO);

		map(partnerVO, bomPartner, false, false);
		if (partnerVO instanceof CustomerVO) {
			map((CustomerVO) partnerVO, bomPartner.getCustomer(), false, false);
		}

		map(bomPartner, partnerVO, false, true);
		if (partnerVO instanceof CustomerVO) {
			map(bomPartner.getCustomer(), (CustomerVO) partnerVO, false, false);
		}

		logMethodEnd("CustomerInformationManager", "updatePartner");
		return partnerVO;
	}
}
